﻿package core.ui.dialogs
{
    import core.event.*;
    import core.ui.controls.*;
    import flash.events.*;

    public class ImageSizeDialog extends Dialog
    {
        var oh:int;
        var ow:int;
        var tbw:Dropslider;
        var tbh:Dropslider;
        var cp:Checkbox;

        public function ImageSizeDialog(param1:Tuyitu)
        {
            super(param1, "rm_image_size", 320, 150, true);
            this.oh = param1.canvas.document.dh;
            this.ow = param1.canvas.document.dw;
            this.cp = new Checkbox("rm_constrain_proportions");
            this.cp.x = 80;
            this.cp.y = 85;
            addChild(this.cp);
            this.cp.Check();
            var _loc_2:* = new Literal("rm_height", true);
            _loc_2.x = 10;
            _loc_2.y = 55;
            _loc_2.width = 70;
            addChild(_loc_2);
            this.tbh = new Dropslider(55, 0, 4000, this.oh);
            this.tbh.addEventListener(SliderEvent.DRAG, this.HeightChange, false, 1, true);
            this.tbh.x = 80;
            this.tbh.y = 55;
            addChild(this.tbh);
            var _loc_3:* = new Literal("rm_pixels");
            _loc_3.x = 138;
            _loc_3.y = 55;
            addChild(_loc_3);
            var _loc_4:* = new Literal("rm_width", true);
            _loc_4.x = 10;
            _loc_4.y = 30;
            _loc_4.width = 70;
            addChild(_loc_4);
            this.tbw = new Dropslider(55, 0, 4000, this.ow);
            this.tbw.addEventListener(SliderEvent.DRAG, this.WidthChange, false, 1, true);
            this.tbw.x = 80;
            this.tbw.y = 30;
            addChild(this.tbw);
            var _loc_5:* = new Literal("rm_pixels");
            _loc_5.x = 138;
            _loc_5.y = 30;
            addChild(_loc_5);
            var _loc_6:int = 239;
            cancel.x = 239;
            ok.x = _loc_6;
            ok.y = 25;
            cancel.y = 54;
            return;
        }// end function

        private function WidthChange(... args) : void
        {
            if (this.cp.checked)
            {
                this.tbh.Set(Math.round(this.tbw.value * this.oh / this.ow));
            }
            return;
        }// end function

        private function HeightChange(... args) : void
        {
            if (this.cp.checked)
            {
                this.tbw.Set(Math.round(this.tbh.value * this.ow / this.oh));
            }
            return;
        }// end function

        override public function OKClick(event:MouseEvent) : void
        {
            if (this.tbw.value != this.ow || this.tbh.value != this.oh)
            {
                ed.canvas.ResizeImage(this.tbw.value, this.tbh.value);
            }
            Close();
            return;
        }// end function

    }
}
